import math

def is_prime(num):
    if num < 2:
        return False
    for i in range(2, int(math.sqrt(num)) + 1):
        if num % i == 0:
            return False
    return True

def find_nearest_prime(num):
    if is_prime(num):
        return num

    lower = num - 1
    upper = num + 1

    while True:
        if is_prime(lower):
            return lower
        elif is_prime(upper):
            return upper
        else:
            lower -= 1
            upper += 1

def main():
    words = input().split()
    
    if len(words) != 3:
        print("Wrong input")
        return

    number = 0
    for i in range(3):
        if words[i] == "one":
            number += 1 * pow(10, 2 - i)
        elif words[i] == "two":
            number += 2 * pow(10, 2 - i)
        elif words[i] == "three":
            number += 3 * pow(10, 2 - i)
        elif words[i] == "four":
            number += 4 * pow(10, 2 - i)
        elif words[i] == "five":
            number += 5 * pow(10, 2 - i)
        elif words[i] == "six":
            number += 6 * pow(10, 2 - i)
        elif words[i] == "seven":
            number += 7 * pow(10, 2 - i)
        elif words[i] == "eight":
            number += 8 * pow(10, 2 - i)
        elif words[i] == "nine":
            number += 9 * pow(10, 2 - i)
        elif words[i] == "zero":
            number += 0 * pow(10, 2 - i)
        else:
            print("Wrong input")
            return

    if number < 100 or number > 999 or number % 100 == 0:
        print("Wrong input")
        return

    nearest_prime = find_nearest_prime(number)
    print(nearest_prime)

if __name__ == "__main__":
    main()